package com.fleamarket.login;

import java.io.IOException;
import java.sql.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;


import com.opensymphony.xwork2.ActionSupport;

/**
 * 登陆认证后台
 * 
 * @author 谭仰芳
 *
 */
public class Login extends ActionSupport{
   
	public String name;
	public String password;
	
     public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String excute()throws IOException{
    	 
		try{
			Class.forName("org.gjt.mm.mysql.Driver").newInstance();//建立数据库的驱动类
			
			String dbURL="jdbc:mysql://localhost:3306/fleamarket";//数据库连接地址
			
			//创建数据库连接，传入数据库地址，用户和密码
			Connection connection=DriverManager.getConnection(dbURL,"root","root");
			
			//创建statement对象，为传入执行SQL语句做准备
			Statement stmt=connection.createStatement();
			//SQL语句
	        String sql="select * from user where user_account ='"+name+"' and password= '"+password+"'";
			
			//创建结果集对象用来保存查询结果			
			ResultSet rs=stmt.executeQuery(sql);
			
			if(rs.next()){
				return "success";
			}
			else {return "failed";}
			
		}catch (Exception e) {
			// TODO: handle exception
			return "failed";
		}
		
	}
	}
		
	
	

